using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLThuChi.Repositories
{
	#region using
	using QLThuChi.Models;
	#endregion
	public class LoaiNhanCongRepository
	{
		public static List<LoaiNhanCong> SelectAll()
		{
			return DataContext.Instance.LoaiNhanCongs.OrderBy(item => item.TenLoaiNhanCong).ToList();
		}

		public static LoaiNhanCong SelectByID(int maloainhancong)
		{
			return DataContext.Instance.LoaiNhanCongs.FirstOrDefault(item => item.MaLoaiNhanCong == maloainhancong );
		}

		public static bool Insert(LoaiNhanCong obj)
		{
			try
			{
				DataContext.Instance.LoaiNhanCongs.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int maloainhancong)
		{
			try
			{
				var delitem = DataContext.Instance.LoaiNhanCongs.FirstOrDefault(item => item.MaLoaiNhanCong == maloainhancong );
				DataContext.Instance.LoaiNhanCongs.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<LoaiNhanCong> RetrieveByID(int maloainhancong)
		{
			return (from item in DataContext.Instance.LoaiNhanCongs where  item.MaLoaiNhanCong == maloainhancong  select item).ToList();
		}

	}
}